package com.hymjweb.demo.framework.util.util;

import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ResultSetMetaDataWrap {

	private int columnCount = -1;

	private List<String> listColumnName = new ArrayList<String>();

	public ResultSetMetaDataWrap() {

	}
	
	/**
	 * 保存游标元信息里的字段名称
	 * @param rsm
	 * @throws SQLException
	 */
	public void init(ResultSetMetaData rsm) throws SQLException {
		this.columnCount = rsm.getColumnCount();
		for (int i = 1; i <= this.columnCount; i++) {
			String columnName = rsm.getColumnName(i);
			listColumnName.add(columnName);
		}
	}

	public int getColumnCount() {
		return this.columnCount;
	}

	/**
	* Get the designated column's name.
	* @param column the first column is 1, the second is 2, ...
	* @return column name
	*/
	public String getColumnName(int column) {
		return listColumnName.get(column - 1);
	}

}
